package com.yunyao.framework.service.impl;

import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.dao.model.BamuFileInfo;
import com.yunyao.dao.model.SysMenu;
import com.yunyao.dao.model.User;
import com.yunyao.dao.service.bamu.IBamuFileInfoService;
import com.yunyao.dao.service.system.ISysMenuService;
import com.yunyao.dao.service.system.ISysRoleService;
import com.yunyao.dao.service.system.IUserService;
import com.yunyao.framework.dto.file.FileInfoDto;
import com.yunyao.framework.service.FileInfoService;
import com.yunyao.framework.service.system.MenuService;
import com.yunyao.framework.vo.file.FileInfoVo;
import com.yunyao.framework.vo.system.MenuVO;
import com.yunyao.framework.vo.system.Meta;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chenyejian
 * @date 2024-07-16
 */
@Slf4j
@Service
public class FileInfoServiceImpl implements FileInfoService {
    @Autowired
    private IBamuFileInfoService iBamuFileInfoService;

    /**
     * 保存并返回主键
     * @param fileInfoDto
     */
    @Override
    public String saveFileInfo(FileInfoDto fileInfoDto) {
        BamuFileInfo fileInfo =convertDto2Dao(fileInfoDto);
        iBamuFileInfoService.save(fileInfo);
        return fileInfo.getId();
    }

    @Override
    public FileInfoVo getFileInfoById(String id) {
        BamuFileInfo fileInfo = iBamuFileInfoService.getById(id);
        return convertDao2Vo(fileInfo);
    }

    @Override
    public Boolean deleteFileInfoById(String id) {
        BamuFileInfo fileInfo = iBamuFileInfoService.getById(id);
        if (fileInfo != null) {
            fileInfo.setIsDeleted(DataDeletedStatus.YES.getType());
            return iBamuFileInfoService.saveOrUpdate(fileInfo);
        }
        return false;
    }

    private BamuFileInfo convertDto2Dao(FileInfoDto fileInfoDto) {
        BamuFileInfo fileInfo = new BamuFileInfo();
        BeanUtils.copyProperties(fileInfoDto, fileInfo);
        return fileInfo;
    }

    private  FileInfoVo convertDao2Vo(BamuFileInfo fileInfo) {
        FileInfoVo fileInfoVo = new FileInfoVo();
        BeanUtils.copyProperties(fileInfo, fileInfoVo);
        return fileInfoVo;
    }
}
